<?php session_start(); ob_start();
	require_once('connect.php');
	$id=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Free Hotel Website Template - designed by TemplateMonster</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="description" content="This is a wonderful homepage of the Free Hotel Website Template provided by TemplateMonster."/>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script src="maxheight.js" type="text/javascript"></script>
</head>
<body id="page1" onload="new ElementMaxHeight();">
<div id="main">
<!-- header -->
	<div id="header">
		<div class="row-1">
			<div class="wrapper">
				<div class="logo">
					<h1><a href="index.html">Indonesian Hotels</a></h1>
					<em>Hotel</em>
					<strong>True Luxury</strong>
				</div>
				
			</div>
		</div>
		<div class="row-2">
	 		<div class="indent">
<!-- header-box begin -->
				<div class="header-box">
					<div class="inner">
						<ul class="nav">
					 		<li><a href="index.php">Home page</a></li>
							<li><a href="services.php">Room and Rates</a>
							<ul>
								<li><a href="indo1.php" target="_self">Indonesian Hotels 1</a></li>
								<li><a href="indo2.php" target="_self">Indonesian Hotels 2</a></li>
								<li><a href="indo3.php" target="_self">Indonesian Hotels 3</a></li>
								<li><a href="indo4.php" target="_self">Indonesian Hotels 4</a></li>
								<li><a href="indo5.php" target="_self">Indonesian Hotels 5</a></li>
								<li><a href="indo6.php" target="_self">Indonesian Hotels 6</a></li>
								<li><a href="indo7.php" target="_self">Indonesian Hotels 7</a></li>
							</ul>
							
							</li>
							<li><a href="booking.php" class="current">Booking</a>
							<ul>
								<li><a href="bookindo1.php" target="_self">Indonesian Hotels 1</a></li>
								<li><a href="bookindo2.php" target="_self">Indonesian Hotels 2</a></li>
								<li><a href="bookindo3.php" target="_self">Indonesian Hotels 3</a></li>
								<li><a href="bookindo4.php" target="_self">Indonesian Hotels 4</a></li>
								<li><a href="bookindo5.php" target="_self">Indonesian Hotels 5</a></li>
								<li><a href="bookindo6.php" target="_self">Indonesian Hotels 6</a></li>
								<li><a href="bookindo7.php" target="_self">Indonesian Hotels 7</a></li>
							</ul>

							</li>
							<li><a href="location.php">Location</a></li>
							<li><a href="gallery.php">Gallery</a></li>
							<li><a href="contact.php">Contact Us</a></li>
						</ul>
					</div>
				</div>
<!-- header-box end -->
			</div>
		</div>
	</div><div class="ic">Lovely Flash templates from TemplateMonster!</div>
<!-- content -->
	<div id="content">
		<div class="wrapper">
			<div class="aside maxheight">
<!-- box begin -->
				<div class="box maxheight">
					<div class="inner">
						<?php
					//	include_once("form_reservasi.php");
						?>
					</div>
				</div>
<!-- box end -->
			</div>
			<div id="content">
				<div class="indent">
					<h2>Indonesian Hotels 1</h2>
					<h3>1 Room Reservation</h3>
					<form action = "<?php echo $PHP_SELF;?>" method="post" name="formdate" id="formdate">
						<table border="1">
						<tr>
							<td>Check-in [yyyy-mm-dd]</td>
							<td><input type="text" name="checkin" id="checkin" style="width:400;"/></td>
						</tr>
						<tr>
							<td>Check-out [yyyy-mm-dd]</td>
							<td><input type="text" name="checkout" id="checkout" style="width:400; ?>""/></td>
						</tr>
						<tr>
							<td>Occupants per Room</td>
							<td>
							<select name="qty_org">
							<?php
							for($i=1;$i<=4;$i++){
								echo "<option value=$i>$i</option>";
							}
							?>
							</select>
							</td>
						</tr>						<tr>
							<td>number of rooms</td>
							<td>
							<select name="qty_room">
							<?php
							for($i=1;$i<=10;$i++){
								echo "<option value=$i>$i</option>";
							}
							?>
							</select>
							</td>
						</tr>
						<tr>
						<td>&nbsp</td>
						<td>
						<input type="hidden" name="id" id="id" value="<?php echo $id;?>"/>
						<input type="submit" name="create" id="button" value="check availability"/></td>
						</tr>
						</table>
					</form>
				</div>
			</div>

		</div>
	</div>
	
<!-- footer -->
	<div id="footer">
  		<ul class="nav">
	 		<li><a href="index.html">Home</a>|</li>
			<li><a href="services.html">Services</a>|</li>
			<li><a href="gallery.html">Gallery</a>|</li>
			<li><a href="restaurant.html">Restaurant</a>|</li>
			<li><a href="testimonials.html">Testimonials</a>|</li>
			<li><a href="booking.html">Booking</a></li>
		</ul>
		<div class="wrapper">
			<div class="fleft">Copyright (c) 2012 Indonesian Hotels</div>
		</div>
	</div>
</div>
</body>
</html>
<?php
	$cekin=$_POST['checkin'];
	$cekout=$_POST['checkout'];
	$qty_org=$_POST['qty_org'];
	$qty_room=$_POST['qty_room'];
	$id_hotel=$_POST['id'];
	
	
	$today = strtotime(date("Y-m-d"));
	$year_cekin=(int)substr($cekin,0,4);
	$month_cekin=(int)substr($cekin,5,2);
	$day_cekin=(int)substr($cekin,8,2);
	$year_cekout=(int)substr($cekout,0,4);
	$month_cekout=(int)substr($cekout,5,2);
	$day_cekout=(int)substr($cekout,8,2);
	$date_cekin = strtotime($cekin);
	$date_cekout = strtotime($cekout);
	$qty_night=$date_cekout-$date_cekin;

if($cekin!='' AND $cekout!=''){
if(preg_match("#[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])#", $cekin) AND preg_match("#[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])#", $cekout)) {	
	if(checkdate($month_cekin ,$day_cekin ,$year_cekin) AND checkdate($month_cekout ,$day_cekout ,$year_cekout))
	{
		if($date_cekout>$date_cekin AND $date_cekin>=$today){
		
			$_SESSION['id_hotel']=$id_hotel;
			$_SESSION['cekin']=$cekin;
			$_SESSION['cekout']=$cekout;
			$_SESSION['qty_org']=$qty_org;
			$_SESSION['qty_room']=$qty_room;
			$_SESSION['qty_night']=$qty_night;
			
			header('Location:display_room.php');
		}	else
			{?>
			<script language="javascript">
			alert( "check-in value must be greater equal today and check-out value must be greater than check-in");
			</script>
	
			<?php
			}

	}else {
	?>
		<script language="javascript">
			alert("check-in and check-out value is not valid");
			</script>
<?php
	}
}else
{?>
			<script language="javascript">
			alert("check-in and check-out format is yyyy-mm-dd");
			</script>
<?php
}
}
?>	
